//
//  MacroUI.swift
//  UI
//
//  Created by mini on 2025/4/28.
//

import Foundation
import UIKit

let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height

// 判断是否为刘海屏
func deviceIsBangsScreen() -> Bool {
    let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
    let bottom = scene?.windows.first?.safeAreaInsets.bottom ?? 0
    return bottom > 0
}
// 判断是否为灵动岛屏幕
let deviceIsSmartIslandScreen = gainDeviceIsSmartIslandScreen()
func gainDeviceIsSmartIslandScreen() -> Bool {
    if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
        // 检查设备是否为 Smart Island（灵动岛） 屏幕
        let deviceIsSmartIslandScreen = (windowScene.windows.first?.safeAreaInsets.top ?? 0 > 44)
        return deviceIsSmartIslandScreen
    }
    return false
}

// 状态栏高度
var STATUSBAR_HEIGHT: CGFloat {
    if #available(iOS 13.0, *) {
        let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
        let statusBarManager = windowScene?.statusBarManager
        return statusBarManager?.statusBarFrame.height ?? 0
    } else {
        return UIApplication.shared.statusBarFrame.height
    }
}

// 导航栏
var NAVIGATIONBAR_HEIGHT: CGFloat {
    return 44.0 + STATUSBAR_HEIGHT
}

// 工具栏高度 (或者改为动态获取 getBottomSafeAreaHeight + 49.0)
let TABBAR_HEIGHT = (deviceIsBangsScreen() ? 83.0 : 49.0)
// 底部安全区域的高度
func getBottomSafeAreaHeight() -> CGFloat {
    if #available(iOS 15.0, *) {
        if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
           let window = windowScene.windows.first
        {
            return window.safeAreaInsets.bottom
        }
    } else {
        return UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 0
    }
    return 0
}


let LEFT_MARGIN = 16.0
let BUTTON_HEIGHT = 47.0
